package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.XtConstants;
import com.ruoyi.system.domain.Huodongbiao;
import com.ruoyi.system.domain.Zhuanjiabiao;
import com.ruoyi.system.service.AppIZhuanjiabiaoService;
import com.ruoyi.system.service.IHuodongbiaoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Anonymous
@RequestMapping("/system/appzhuanjiabiao")
public class AppZhuanjiabiaoController extends BaseController {

  @Autowired
  private IHuodongbiaoService huodongbiaoService;

    @Autowired(required = false)
    private AppIZhuanjiabiaoService appzhuanjiabiaoService;
    /**
     * 查询专家信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:zhuanjiabiao:query')")
    @GetMapping("/list")
    public TableDataInfo list(String str)
    {
        startPage();
        List<Zhuanjiabiao> list = appzhuanjiabiaoService.SelectZhuanjiabiaoLike(str);

      for(Zhuanjiabiao zj :list){

        int count=0;//用于计算活动次数
        Double pfSum=0.0;//活动评分总和

        // 活动次数封装
        Huodongbiao huodong = new Huodongbiao();
        huodong.setZj(zj.getZjName());
        //获取该专家参加过的所有活动，只不过条件是按照专家姓名来查询
        List<Huodongbiao> huodongbiaos = huodongbiaoService.selectHuodongbiaoList(huodong);
        for (Huodongbiao huodongbiao:huodongbiaos){
          count++;
          pfSum+=huodongbiao.getHdpf();
        }
        //获得专家列表，把里面对应的键key，替换成对应的值value
        zj.setHdcs(String.valueOf(count));
        zj.setHdhp(String.valueOf((int)(pfSum/(count*5)*100)));
        zj.setImage(XtConstants.BASE_URL+zj.getImage());
        zj.setZzmm(XtConstants.ZZMM_MAP.get(zj.getZzmm()));
        zj.setXl(XtConstants.XL_MAP.get(zj.getXl()));
        zj.setZjlx(XtConstants.ZJLX_MAP.get(zj.getZjlx()));
        zj.setZc(XtConstants.ZZ_MAP.get(zj.getZc()));

      }
      return getDataTable(list);
    }


  /**
   * 获取专家管理详细信息
   */
  @PreAuthorize("@ss.hasPermi('system:zhuanjiabiao:query')")
  @GetMapping(value = "/zjxq")
  @ApiOperation("获取专家详细信息")
  public AjaxResult getInfo(@RequestParam("id") Long zjId)
  {
    Zhuanjiabiao zjb = appzhuanjiabiaoService.selectZhuanjiabiaoByZjId(zjId);
    zjb.setImage(XtConstants.BASE_URL +zjb.getImage());
    zjb.setXl(XtConstants.XL_MAP.get(zjb.getXl()));
    zjb.setZzmm(XtConstants.ZZMM_MAP.get(zjb.getZzmm()));
    zjb.setXl(XtConstants.XL_MAP.get(zjb.getXl()));
    zjb.setZjlx(XtConstants.ZJLX_MAP.get(zjb.getZjlx()));
    zjb.setZc(XtConstants.ZZ_MAP.get(zjb.getZc()));

    return success(zjb);
  }

}
